* This file cleans and analyzes the bargaining data

clear
set more off
insheet using bargaining_data.csv, names


/*
	CLEANING
*/


* Label the sessions

gen session = .

replace session = 1 if session_time == "170801_0937"
replace session = 2 if session_time == "170801_1348"
replace session = 3 if session_time == "170912_0859"
replace session = 4 if session_time == "170919_0921"
replace session = 5 if session_time == "170921_0904"
replace session = 6 if session_time == "170925_0851"
replace session = 7 if session_time == "170925_1145"
replace session = 8 if session_time == "170926_0915"
replace session = 9 if session_time == "171003_0915"
replace session = 10 if session_time == "171003_1146"
replace session = 11 if session_time == "171005_0919"
replace session = 12 if session_time == "171005_1149"
replace session = 13 if session_time == "171012_1332"
replace session = 14 if session_time == "171025_1036"
replace session = 15 if session_time == "171026_1031"
replace session = 16 if session_time == "171121_1238"
replace session = 17 if session_time == "171122_1243"
replace session = 18 if session_time == "171127_1240"
replace session = 19 if session_time == "181109_0926"
replace session = 20 if session_time == "181123_1318"
replace session = 21 if session_time == "181127_1335"
replace session = 22 if session_time == "181204_1452"
replace session = 23 if session_time == "190227_1032"
replace session = 24 if session_time == "190308_1132"
replace session = 25 if session_time == "190315_1027"
replace session = 26 if session_time == "190322_1233"
replace session = 27 if session_time == "190403_0927"
replace session = 28 if session_time == "190503_1044"
replace session = 29 if session_time == "190510_1132"
replace session = 30 if session_time == "190516_1034"
replace session = 31 if session_time == "210915_1538"
replace session = 32 if session_time == "211005_1539"
replace session = 33 if session_time == "211006_1533"
replace session = 34 if session_time == "211007_1435"

drop session_time
drop if session == .
order session


* Label the treatments

gen alternating = .
	replace alternating = 0 if treatment == 14 | treatment == 22 | treatment == 41 | treatment == 51
	replace alternating = 1 if treatment == 13 | treatment == 21 | treatment == 61

gen goods = .
	replace goods = 1 if treatment == 13 | treatment == 14
	replace goods = 4 if treatment == 21 | treatment == 22 | treatment == 41 | treatment == 51 | treatment == 61

gen treat = (goods - 1) / 3
gen surplus_known = 1
	replace surplus_known = 0 if treatment == 41 | treatment == 51 | treatment == 61

gen coin = 0
	replace coin = 1 if treatment == 41
gen wheel = 0
	replace wheel = 1 if treatment == 51
gen onetoone = 0
	replace onetoone = 1 if treatment == 61

order session treatment treat alternating goods surplus_known coin wheel onetoone


* Label the periods

gen practice = .
	replace practice = 1 if period <= 0
	replace practice = 0 if period > 0

foreach X in 1 2 3 4 5 6 {

gen period_`X' = 0
	replace period_`X' = 1 if period == `X'

}

order session treatment alternating goods surplus_known coin wheel onetoone period period_* practice


* Eliminate practice data and bad trade data

drop if efficiency == -1

drop if practice == 1
drop practice


* Calculate efficiency

gen efficiency_basic = .
	replace efficiency_basic = efficiency if surplus > 0

gen efficiency_alt = .
	replace efficiency_alt = efficiency if surplus > 0
	replace efficiency_alt = 1 if surplus <= 0


* Bargaining rounds have two definitions

rename bargaining_rounds bargaining_rounds_raw
gen bargaining_rounds = .

foreach X in 1 2 3 4 5 6 7 8 {
	scalar x1 = 1 - ((`X' - 1) * 0.1) - 0.0000001
	scalar x2 = 1 - ((`X' - 1) * 0.1) + 0.0000001
	replace bargaining_rounds = `X' if bargaining_rounds_raw == `X' & efficiency > x1 & efficiency < x2 & treatment != 61
}

replace bargaining_rounds = 9 if (bargaining_rounds_raw == 9 & efficiency == 0 & treatment != 61) | (bargaining_rounds == . & treatment != 61)

	
* Generating trading variables

gen trade = .
	replace trade = 0 if (bargaining_rounds_raw == 9 & onetoone == 0) | (efficiency == 0 & onetoone == 1)
	replace trade = 1 if (bargaining_rounds_raw <= 8 & onetoone == 0) | (efficiency > 0 & onetoone == 1)

sort session period group
by session period: egen trade_p_ = mean(trade) if surplus > 0
by session period: egen trade_p = mean(trade_p_)
drop trade_p_

sort session period group
by session: egen trade_s_ = mean(trade) if surplus > 0
by session: egen trade_s = mean(trade_s_)
drop trade_s_

sort treatment session group period
by treatment: egen trade_t_ = mean(trade) if surplus > 0
by treatment: egen trade_t = mean(trade_t_)
drop trade_t_


* Identifiers for period-level and session-level data for statistical analysis

sort session period group

by session period: gen data_period = _n
	replace data_period = 0 if data_period > 1

by session: gen data_session = _n
	replace data_session = 0 if data_session > 1

sort treatment session period group

by treatment: gen data_treatment = _n
	replace data_treatment = 0 if data_treatment > 1

	
* Create unweighted sample means for statistical analysis

sort session period group
by session period: egen efficiency_basic_p_u = mean(efficiency_basic)

sort session period group
by session: egen efficiency_basic_s_u = mean(efficiency_basic)

sort treatment session period group
by treatment: egen efficiency_basic_t = mean(efficiency_basic)


* Create weighted sample means for statistical analysis

gen w = surplus
	replace w = 0 if w < 0
gen x = efficiency_basic * w

sort session period group
by session period: egen sum_w_p = sum(w)
by session period: egen sum_x_p = sum(x)
gen efficiency_basic_p_w = sum_x_p / sum_w_p

sort session period group
by session: egen sum_w_s = sum(w)
by session: egen sum_x_s = sum(x)
gen efficiency_basic_s_w = sum_x_s / sum_w_s

sort treatment
by treatment: egen sum_w_t = sum(w)
by treatment: egen sum_x_t = sum(x)
gen efficiency_basic_w_t = sum_x_t / sum_w_t

egen sum_w = sum(w)
egen sum_x = sum(x)
gen efficiency_basic_w = sum_x / sum_w

drop w x sum_w_p sum_x_p sum_w_s sum_x_s sum_w_t sum_x_t sum_w sum_x
	

* Time distribution of profits

gen profit = efficiency / (1 - (0.1 * (bargaining_rounds_raw - 1))) if treatment != 61

foreach X in 1 2 3 4 5 6 7 8 {
	gen profit_`X' = 0 if treatment != 61 & surplus > 0
	replace profit_`X' = profit if treatment != 61 & bargaining_rounds_raw == `X' & surplus > 0
}

gen profit_lost = 0 if treatment != 61 & surplus > 0
	replace profit_lost = 1 - profit if (treatment == 21 | treatment == 22 | treatment == 41 | treatment == 51)
	replace profit_lost = 1 if bargaining_rounds_raw == 9 & (treatment == 13 | treatment == 14) & surplus > 0

foreach X in 1 2 3 4 5 6 7 8 lost {
	sort treatment
	by treatment: egen profit_`X'_t = mean(profit_`X')
}


* # Subjects in each session/treatment

sort session period group
by session: egen a = max(group)
gen subjects_session = 2 * a
drop a

sort treatment
by treatment: egen subjects_treatment = sum(subjects_session) if data_session == 1

	
* Clean up

sort session period group
save bargaining_data.dta, replace


* Operations specific to one-to-one treatment data

clear
insheet using "bargaining_data_one_by_one.csv", names
drop if period < 1

foreach X in 1 2 3 4 {
	gen profit_good_`X' = 0
	replace profit_good_`X' = (valuesbuyer`X' - valuesseller`X') / 70 if roundsbargained`X' != 9999
	foreach Y in 1 2 3 4 5 6 7 8 {
		gen trade_good_`X'_in_round_`Y' = 0
		replace trade_good_`X'_in_round_`Y' = 1 if roundsbargained`X' == `Y'
	}
}

foreach Y in 1 2 3 4 5 6 7 8 {
	gen profit_`Y' = 0
	replace profit_`Y' = (profit_good_1 * trade_good_1_in_round_`Y') + (profit_good_2 * trade_good_2_in_round_`Y') + (profit_good_3 * trade_good_3_in_round_`Y') + (profit_good_4 * trade_good_4_in_round_`Y')
}

gen profit_lost = 1 - profit_good_1 - profit_good_2 - profit_good_3 - profit_good_4
	replace profit_lost = 0 if profit_lost < 0.0001

foreach X in 1 2 3 4 5 6 7 8 {
	sum profit_`X'
	scalar t61b_`X' = round(r(mean), 0.001)
}

sum profit_lost
scalar t61b_9 = round(r(mean), 0.001)

scalar t61_1 = 0.013
scalar t61_2 = 0.158
scalar t61_3 = 0.188
scalar t61_4 = 0.107
scalar t61_5 = 0.090
scalar t61_6 = 0.073
scalar t61_7 = 0.064
scalar t61_8 = 0.064
scalar t61_9 = 0.244

clear


/*
	TRUTH DATA
*/

insheet using "bargaining_data_truth_1.csv", names

drop if period < 1
drop if bargain_round == 9
drop if declaration2 == .
gen observation = 1
gen true = .
	replace true = 0 if declaration2 != .
	replace true = 1 if declaration2 == value

sort bargain_round
by bargain_round: egen total_obs_by_br = total(observation)
by bargain_round: egen total_true_by_br = total(true)
by bargain_round: gen total_untrue_by_br = total_obs_by_br - total_true_by_br
by bargain_round: gen data = _n

egen total_obs = total(observation)
egen total_true = total(true)
gen total_untrue = total_obs - total_true
gen perc_total_untrue = total_untrue / total_obs

egen x_1 = sum(total_obs_by_br) if data == 1
egen y_1 = sum(total_untrue_by_br) if data == 1
gen z_1 = y_1/x_1

save bargaining_data_truth_1, replace
clear

insheet using "bargaining_data_truth_4.csv", names

drop if disclose == .
drop if disclose == 0

sort Treatment bargain_round
bysort Treatment bargain_round: egen total_obs_by_br = total(disclose)
bysort Treatment bargain_round: egen total_true_by_br = total(truth)
bysort Treatment bargain_round: gen total_untrue_by_br = total_obs_by_br - total_true_by_br

bysort Treatment: egen total_obs = total(disclose)
bysort Treatment: egen total_true = total(truth)
bysort Treatment: gen total_untrue = total_obs - total_true
bysort Treatment: gen perc_total_untrue = total_untrue / total_obs

by Treatment bargain_round: gen data = _n

egen x_2 = sum(total_obs_by_br) if data == 1 & Treatment == 22
egen y_2 = sum(total_untrue_by_br) if data == 1 & Treatment == 22
gen z_2 = y_2/x_2

egen x_3 = sum(total_obs_by_br) if data == 1 & Treatment == 41
egen y_3 = sum(total_untrue_by_br) if data == 1 & Treatment == 41
gen z_3 = y_3/x_3

egen x_4 = sum(total_obs_by_br) if data == 1 & Treatment == 51
egen y_4 = sum(total_untrue_by_br) if data == 1 & Treatment == 51
gen z_4 = y_4/x_4


save bargaining_data_truth_4, replace
clear

use bargaining_data

log using bargaining_results.log, replace


/*
	FIGURES IN TABLES IN THE PAPER
*/


log off


* Table 1

sum subjects_treatment if treatment == 13
	scalar t1_r1_c1 = r(mean)
sum subjects_treatment if treatment == 14
	scalar t1_r2_c1 = r(mean)
sum subjects_treatment if treatment == 61
	scalar t1_r3_c1 = r(mean)
sum subjects_treatment if treatment == 21
	scalar t1_r4_c1 = r(mean)
sum subjects_treatment if treatment == 22
	scalar t1_r5_c1 = r(mean)
sum subjects_treatment if treatment == 41
	scalar t1_r6_c1 = r(mean)
sum subjects_treatment if treatment == 51
	scalar t1_r7_c1 = r(mean)

count if data_session == 1 & treatment == 13
	scalar t1_r1_c2 = r(N)
count if data_session == 1 & treatment == 14
	scalar t1_r2_c2 = r(N)
count if data_session == 1 & treatment == 61
	scalar t1_r3_c2 = r(N)
count if data_session == 1 & treatment == 21
	scalar t1_r4_c2 = r(N)
count if data_session == 1 & treatment == 22
	scalar t1_r5_c2 = r(N)
count if data_session == 1 & treatment == 41
	scalar t1_r6_c2 = r(N) 
count if data_session == 1 & treatment == 51
	scalar t1_r7_c2 = r(N) 

	
log on

display "" _newline "TABLE 1" _newline "Label     | # Goods | Information/Protocol        | Subjects (sessions)" _newline "-----------------------------------------------------------------------" _newline "1-IN-OBO  | 1       | Independent one-by-one      | " scalar(t1_r1_c1) " (" scalar(t1_r1_c2) ")             " _newline "1-IN-FF   | 1       | Independent free-form       | " scalar(t1_r2_c1) " (" scalar(t1_r2_c2) ")             " _newline "4-IN-FF   | 4       | Independent free-form       | " scalar(t1_r6_c1) " (" scalar(t1_r6_c2) ")             " _newline "4-KF-FF   | 4       | Known frequencies free-form | " scalar(t1_r7_c1) " (" scalar(t1_r7_c2) ")             " _newline "4-KS-OBO  | 4       | Known surplus one-by-one    | " scalar(t1_r3_c1) " (" scalar(t1_r3_c2) ")             " _newline "4-KS-Comb | 4       | Known surplus combinatorial | " scalar(t1_r4_c1) " (" scalar(t1_r4_c2) ")             " _newline "4-KS-FF   | 4       | Known surplus free form     | " scalar(t1_r5_c1) " (" scalar(t1_r5_c2) ")             "

log off
	
	
* Table 2 + Table 5

sum efficiency_basic_s_w if data_session == 1 & treatment == 13
	scalar t2_r1_c1_1 = round(r(mean),0.001)
	scalar t2_r1_c1_2 = round(r(sd),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 61
	scalar t2_r1_c2_1 = round(r(mean),0.001)
	scalar t2_r1_c2_2 = round(r(sd),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 13
	scalar t2_r2_c1_1 = round(r(mean),0.001)
	scalar t2_r2_c1_2 = round(r(sd),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 21
	scalar t2_r2_c2_1 = round(r(mean),0.001)
	scalar t2_r2_c2_2 = round(r(sd),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 14
	scalar t2_r3_c1_1 = round(r(mean),0.001)
	scalar t2_r3_c1_2 = round(r(sd),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 22
	scalar t2_r3_c2_1 = round(r(mean),0.001)
	scalar t2_r3_c2_2 = round(r(sd),0.001)

ttest efficiency_basic_s_w if data_session == 1 & (treatment == 13 | treatment == 61), unequal by(goods)
	scalar t2_r1_c3 = round(r(p) / 2,0.001)
ttest efficiency_basic_s_w if data_session == 1 & (treatment == 13 | treatment == 21), unequal by(goods)
	scalar t2_r2_c3 = round(r(p) / 2,0.001)
ttest efficiency_basic_s_w if data_session == 1 & (treatment == 14 | treatment == 22), unequal by(goods)
	scalar t2_r3_c3 = round(r(p) / 2,0.001)

ttest efficiency_basic_s_w if data_session == 1 & (treatment == 13 | treatment == 14), unequal by(alternating)
	scalar t2_r5_c1 = round(r(p) / 2,0.001)
ttest efficiency_basic_s_w if data_session == 1 & (treatment == 21 | treatment == 61), unequal by(onetoone)
	scalar t2_r4_c2 = round(r(p) / 2,0.001)
ttest efficiency_basic_s_w if data_session == 1 & (treatment == 22 | treatment == 21), unequal by(alternating)
	scalar t2_r5_c2 = round(r(p) / 2,0.001)

ttest efficiency_basic_s_w = 1 if data_session == 1 & treatment == 21
	scalar t2_extra_1 = round(r(p) / 2,0.001)
ttest efficiency_basic_s_w = 1 if data_session == 1 & treatment == 22
	scalar t2_extra_2 = round(r(p) / 2,0.001)

log on

display "" _newline "TABLE 2" _newline "Treatment Description                | Fraction of surplus realized   " _newline "-----------------------------------------------------------------------------" _newline "4-KS-OneByOne                        | " scalar(t2_r1_c2_1) " (" scalar(t2_r1_c2_2) ")" _newline "4-KS-Combinat                        | " scalar(t2_r2_c2_1) " (" scalar(t2_r2_c2_2) ")" _newline "4-KS-FreeForm                        | " scalar(t2_r3_c2_1) " (" scalar(t2_r3_c2_2) ")" _newline "-----------------------------------------------------------------------------" _newline "p-value row 1 vs row 2  " "             | " scalar(t2_r4_c2) "                   " _newline "p-value row 2 vs row 3   " "            | " scalar(t2_r5_c2) "   

* display "" _newline "TABLE 2 + TABLE 5" _newline "Treatment Description  | 1 good      | 4 goods known surplus | p-value" _newline "-----------------------------------------------------------------------------" _newline "Structured one-by-one  | " scalar(t2_r1_c1_1) " (" scalar(t2_r1_c1_2) ") | " scalar(t2_r1_c2_1) " (" scalar(t2_r1_c2_2) ")           | " scalar(t2_r1_c3) _newline "Structured deals       | " scalar(t2_r2_c1_1) " (" scalar(t2_r2_c1_2) ") | " scalar(t2_r2_c2_1) " (" scalar(t2_r2_c2_2) ")           | " scalar(t2_r2_c3) _newline "Free form              | " scalar(t2_r3_c1_1) " (" scalar(t2_r3_c1_2) ") | " scalar(t2_r3_c2_1) " (" scalar(t2_r3_c2_2) ")           | " scalar(t2_r3_c3) _newline "-----------------------------------------------------------------------------" _newline "p-value row 1 vs row 2 |" " N/A         | " scalar(t2_r4_c2) "                  |" _newline "p-value row 2 vs row 3 | " scalar(t2_r5_c1) "         | " scalar(t2_r5_c2) "                   |" _newline "-----------------------------------------------------------------------------" _newline "p-value row 2 = 1 (4 goods, 1-tailed) " scalar(t2_extra_1) _newline "p-value row 3 = 1 (4 goods, 1-tailed) " scalar(t2_extra_2) 

log off
	

* Table 3 + Table 4

sum efficiency_basic_s_w if data_session == 1 & treatment == 14
	scalar t3_r1_1 = round(r(mean),0.001)
	scalar t3_r1_2 = round(r(sd),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 41
	scalar t3_r2_1 = round(r(mean),0.001)
	scalar t3_r2_2 = round(r(sd),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 51
	scalar t3_r3_1 = round(r(mean),0.001)
	scalar t3_r3_2 = round(r(sd),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 22
	scalar t3_r4_1 = round(r(mean),0.001)
	scalar t3_r4_2 = round(r(sd),0.001)

ttest efficiency_basic_s_w if data_session == 1 & (treatment == 41 | treatment == 51), unequal by(wheel)
	scalar t3_r5 = round(r(p) / 2,0.001)
ttest efficiency_basic_s_w if data_session == 1 & (treatment == 51 | treatment == 22), unequal by(surplus_known)
	scalar t3_r6 = round(r(p) / 2,0.001)
ttest efficiency_basic_s_w if data_session == 1 & (treatment == 14 | treatment == 41), unequal by(goods)
	scalar t3_r7 = round(r(p) / 2,0.001)
	
log on

display "" _newline "TABLE 3" _newline "Treatment                                         | Fraction of Surplus Realized" _newline "--------------------------------------------------------------" _newline " 4-IN-FreeForm                                    | " scalar(t3_r2_1) " (" scalar(t3_r2_2) ")" _newline " 4-KF-FreeForm                                    | " scalar(t3_r3_1) " (" scalar(t3_r3_2) ")" _newline " 4-KS-FreeForm                                    | " scalar(t3_r4_1) " (" scalar(t3_r4_2) ")" _newline "--------------------------------------------------------------" _newline "p-value row 1 vs row 2                            | " scalar(t3_r5) _newline "p-value row 2 vs row 3                            | " scalar(t3_r6) 

display "" _newline "TABLE 4" _newline "Treatment                                         | Fraction of Surplus Realized" _newline "--------------------------------------------------------------" _newline " 1-IN-FreeForm                                    | " scalar(t3_r1_1) " (" scalar(t3_r1_2) ")" _newline " 4-IN-FreeForm                                    | " scalar(t3_r2_1) " (" scalar(t3_r2_2) ")" _newline "--------------------------------------------------------------" _newline "p-value row 1 vs row 2                            | " scalar(t3_r7)  

display "" _newline "TABLE 5" _newline "Treatment Description  | 1 good      | 4 goods known surplus | p-value" _newline "-----------------------------------------------------------------------------" _newline "One-by-one             | " scalar(t2_r1_c1_1) " (" scalar(t2_r1_c1_2) ") | " scalar(t2_r1_c2_1) " (" scalar(t2_r1_c2_2) ")           | " scalar(t2_r1_c3) _newline "Free-form              | " scalar(t2_r3_c1_1) " (" scalar(t2_r3_c1_2) ") | " scalar(t2_r3_c2_1) " (" scalar(t2_r3_c2_2) ")           | " scalar(t2_r3_c3) _newline "-----------------------------------------------------------------------------" _newline "p-value row 1 vs row 2 |" scalar(t2_r5_c1) "          | " scalar(t2_r4_c2) "                  |"

* display "" _newline "TABLE 3 + TABLE 4" _newline "Treatment | # Goods | Format                      | Efficiency" _newline "--------------------------------------------------------------" _newline " 2        | 1       | Free-form, unknown          | " scalar(t3_r1_1) " (" scalar(t3_r1_2) ")" _newline " 6        | 4       | Free-form, deals, IID       | " scalar(t3_r2_1) " (" scalar(t3_r2_2) ")" _newline " 7        | 4       | Free-form, deals, known frq | " scalar(t3_r3_1) " (" scalar(t3_r3_2) ")" _newline " 5        | 4       | Free-form, deals, known     | " scalar(t3_r4_1) " (" scalar(t3_r4_2) ")" _newline "--------------------------------------------------------------" _newline "p-value row 2 vs row 3 | " scalar(t3_r5) _newline "p-value row 3 vs row 4 | " scalar(t3_r6) _newline "p-value row 1 vs row 2 | " scalar(t3_r7)

log off

	
* Table 6

sum efficiency_basic_s_w if data_session == 1 & treatment == 13
	scalar t4_r1_c1 = round(r(mean),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 14
	scalar t4_r2_c1 = round(r(mean),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 61
	scalar t4_r3_c1 = round(r(mean),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 21
	scalar t4_r4_c1 = round(r(mean),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 41
	scalar t4_r5_c1 = round(r(mean),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 51
	scalar t4_r6_c1 = round(r(mean),0.001)
sum efficiency_basic_s_w if data_session == 1 & treatment == 22
	scalar t4_r7_c1 = round(r(mean),0.001)

ttest efficiency_basic_s_w if data_session == 1 & (treatment == 13 | treatment == 61), unequal by(goods)
	scalar t4_r3_c2 = round(r(p) / 2,0.001)
ttest efficiency_basic_s_w if data_session == 1 & (treatment == 13 | treatment == 21), unequal by(goods)
	scalar t4_r4_c2 = round(r(p) / 2,0.001)
ttest efficiency_basic_s_w if data_session == 1 & (treatment == 14 | treatment == 41), unequal by(goods)
	scalar t4_r5_c2 = round(r(p) / 2,0.001)
ttest efficiency_basic_s_w if data_session == 1 & (treatment == 14 | treatment == 51), unequal by(goods)
	scalar t4_r6_c2 = round(r(p) / 2,0.001)
ttest efficiency_basic_s_w if data_session == 1 & (treatment == 14 | treatment == 22), unequal by(goods)
	scalar t4_r7_c2 = round(r(p) / 2,0.001)

sum trade_t if treatment == 13
	scalar t4_r1_c3 = round(r(mean), 0.001)
sum trade_t if treatment == 14
	scalar t4_r2_c3 = round(r(mean), 0.001)
sum trade_t if treatment == 61
	scalar t4_r3_c3 = round(r(mean), 0.001)
sum trade_t if treatment == 21
	scalar t4_r4_c3 = round(r(mean), 0.001)
sum trade_t if treatment == 41
	scalar t4_r5_c3 = round(r(mean), 0.001)
sum trade_t if treatment == 51
	scalar t4_r6_c3 = round(r(mean), 0.001)
sum trade_t if treatment == 22
	scalar t4_r7_c3 = round(r(mean), 0.001)

ttest trade_s if data_session == 1 & (treatment == 61 | treatment == 13), unequal by(goods)
	scalar t4_r3_c4 = round(r(p)/2, 0.001)
ttest trade_s if data_session == 1 & (treatment == 21 | treatment == 13), unequal by(goods)
	scalar t4_r4_c4 = round(r(p)/2, 0.001)
ttest trade_s if data_session == 1 & (treatment == 41 | treatment == 14), unequal by(goods)
	scalar t4_r5_c4 = round(r(p)/2, 0.001)
ttest trade_s if data_session == 1 & (treatment == 51 | treatment == 14), unequal by(goods)
	scalar t4_r6_c4 = round(r(p)/2, 0.001)
ttest trade_s if data_session == 1 & (treatment == 22 | treatment == 14), unequal by(goods)
	scalar t4_r7_c4 = round(r(p)/2, 0.001)

log on

display "" _newline "TABLE 6" _newline "Format                      | Efficiency (p-value vs 1 good) | Trade % (p-value vs 1 good)" _newline "--------------------------------------------------------------------------" _newline "1-IN-OneByOne               | " scalar(t4_r1_c1) "                           | " scalar(t4_r1_c3) _newline "1-IN-FreeForm               | " scalar(t4_r2_c1) "                           | " scalar(t4_r2_c3) _newline "4-KS-OneByOne               | " scalar(t4_r3_c1) " (" scalar(t4_r3_c2) ")                    | " scalar(t4_r3_c3) " (" scalar(t4_r3_c4) ")" _newline "4-IN-FreeForm               | " scalar(t4_r5_c1) " (" scalar(t4_r5_c2) ")                    | " scalar(t4_r5_c3) " (" scalar(t4_r5_c4) ")" _newline "4-KS-Combinat               | " scalar(t4_r4_c1) " (" scalar(t4_r4_c2) ")                    | " scalar(t4_r4_c3) " (" scalar(t4_r4_c4) ")" _newline "4-KF-FreeForm               | " scalar(t4_r6_c1) " (" scalar(t4_r6_c2) ")                    | " scalar(t4_r6_c3) " (" scalar(t4_r6_c4) ")" _newline "4-KS-FreeForm               | " scalar(t4_r7_c1) " (" scalar(t4_r7_c2) ")                    | " scalar(t4_r7_c3) " (" scalar(t4_r7_c4) ")"

log off


* Table [removed]

count if treatment == 13 & surplus > 0
	scalar n = r(N)
foreach X in 1 2 3 4 5 6 7 8 9 {
	count if treatment == 13 & surplus > 0 & bargaining_rounds == `X'
	scalar t13_`X' = round(r(N) / n, 0.001)
}

count if treatment == 14 & surplus > 0
	scalar n = r(N)
foreach X in 1 2 3 4 5 6 7 8 9 {
	count if treatment == 14 & surplus > 0 & bargaining_rounds == `X'
	scalar t14_`X' = round(r(N) / n, 0.001)
}	

count if treatment == 21 & surplus > 0
	scalar n = r(N)
foreach X in 1 2 3 4 5 6 7 8 9 {
	count if treatment == 21 & surplus > 0 & bargaining_rounds == `X'
	scalar t21_`X' = round(r(N) / n, 0.001)
}	

count if treatment == 22 & surplus > 0
	scalar n = r(N)
foreach X in 1 2 3 4 5 6 7 8 9 {
	count if treatment == 22 & surplus > 0 & bargaining_rounds == `X'
	scalar t22_`X' = round(r(N) / n, 0.001)
}	

count if treatment == 41 & surplus > 0
	scalar n = r(N)
foreach X in 1 2 3 4 5 6 7 8 9 {
	count if treatment == 41 & surplus > 0 & bargaining_rounds == `X'
	scalar t41_`X' = round(r(N) / n, 0.001)
}	

count if treatment == 51 & surplus > 0
	scalar n = r(N)
foreach X in 1 2 3 4 5 6 7 8 9 {
	count if treatment == 51 & surplus > 0 & bargaining_rounds == `X'
	scalar t51_`X' = round(r(N) / n, 0.001)
}	
log on

* display "" _newline "TABLE 5a" _newline "" _newline "Period                    | ""1    | 2    | 3    | 4    | 5    | 6    | 7    | 8    | No trade" _newline "---------------------------------------------------------------------------------------------" _newline "1 good structured         | " scalar(t13_1) " | " scalar(t13_2) " | " scalar(t13_3) " | " scalar(t13_4) " | " scalar(t13_5) " | " scalar(t13_6) " | " scalar(t13_7) " | " scalar(t13_8) " | " scalar(t13_9) _newline "1 good free-form          | " scalar(t14_1) " | " scalar(t14_2) " | " scalar(t14_3) " | " scalar(t14_4) " | " scalar(t14_5) " | " scalar(t14_6) " | " scalar(t14_7) " | " scalar(t14_8) " | " scalar(t14_9) _newline "4 goods one-by-one        | " scalar(t61_1) " | " scalar(t61_2) " | " scalar(t61_3) " | " scalar(t61_4) " | " scalar(t61_5) "  | " scalar(t61_6) " | " scalar(t61_7) " | " scalar(t61_8) " | " scalar(t61_9) _newline "4 goods structured, deals | " scalar(t21_1) "  | " scalar(t21_2) " | " scalar(t21_3) "  | " scalar(t21_4) " | " scalar(t21_5) " | " scalar(t21_6) " | " scalar(t21_7) " | " scalar(t21_8) "    | " scalar(t21_9) _newline "4 goods free-form, IID    | "  scalar(t41_1) " | " scalar(t41_2) " | " scalar(t41_3) " | " scalar(t41_4) " | " scalar(t41_5) " | " scalar(t41_6) " | " scalar(t41_7) " | " scalar(t41_8) " | " scalar(t41_9) _newline "4 goods free-form, known f| "  scalar(t51_1) " | " scalar(t51_2) " | " scalar(t51_3) " | " scalar(t51_4) " | " scalar(t51_5) " | " scalar(t51_6) "    | " scalar(t51_7) " | " scalar(t51_8) " | " scalar(t51_9) _newline "4 goods free-form         | "  scalar(t22_1) " | " scalar(t22_2) " | " scalar(t22_3) " | " scalar(t22_4) " | " scalar(t22_5) " | " scalar(t22_6) " | " scalar(t22_7) "    | " scalar(t22_8) "    | " scalar(t22_9)

log off

* Table 7

foreach X in 1 2 3 4 5 6 7 8 {
	sum profit_`X'_t if treatment == 21
	scalar t21b_`X' = round(r(mean), 0.001)
}	

sum profit_lost_t if treatment == 21
scalar t21b_9 = round(r(mean), 0.001)

foreach X in 1 2 3 4 5 6 7 8 {
	sum profit_`X'_t if treatment == 22
	scalar t22b_`X' = round(r(mean), 0.001)
}	

sum profit_lost_t if treatment == 22
scalar t22b_9 = round(r(mean), 0.001)

foreach X in 1 2 3 4 5 6 7 8 {
	sum profit_`X'_t if treatment == 41
	scalar t41b_`X' = round(r(mean), 0.001)
}	

sum profit_lost_t if treatment == 41
scalar t41b_9 = round(r(mean), 0.001)

foreach X in 1 2 3 4 5 6 7 8 {
	sum profit_`X'_t if treatment == 51
	scalar t51b_`X' = round(r(mean), 0.001)
}	

sum profit_lost_t if treatment == 51
scalar t51b_9 = round(r(mean), 0.001)


log on

display "" _newline "TABLE 7" _newline "" _newline "Period                    | ""1    | 2    | 3    | 4    | 5    | 6    | 7    | 8    | No trade" _newline "------------------------------------------------------------------------------------------" _newline "1-IN-OneByOne             | " scalar(t13_1) " | " scalar(t13_2) " | " scalar(t13_3) " | " scalar(t13_4) " | " scalar(t13_5) " | " scalar(t13_6) " | " scalar(t13_7) " | " scalar(t13_8) " | " scalar(t13_9) _newline "1-IN-FreeForm             | " scalar(t14_1) " | " scalar(t14_2) " | " scalar(t14_3) " | " scalar(t14_4) " | " scalar(t14_5) " | " scalar(t14_6) " | " scalar(t14_7) " | " scalar(t14_8) " | " scalar(t14_9) _newline "4-KS-OneByOne             | " scalar(t61b_1) " | " scalar(t61b_2) " | " scalar(t61b_3) " | " scalar(t61b_4) " | " scalar(t61b_5) " | " scalar(t61b_6) " | " scalar(t61b_7) " | " scalar(t61b_8) "  | " scalar(t61b_9) _newline "4-IN-FreeForm             | "  scalar(t41b_1) " | " scalar(t41b_2) " | " scalar(t41b_3) " | " scalar(t41b_4) " | " scalar(t41b_5) " | " scalar(t41b_6) " | " scalar(t41b_7) " | " scalar(t41b_8) "  | " scalar(t41b_9) _newline "4-KS-Combinat             | " scalar(t21b_1) " | " scalar(t21b_2) " | " scalar(t21b_3) " | " scalar(t21b_4) " | " scalar(t21b_5) " | " scalar(t21b_6) " | " scalar(t21b_7) " | " scalar(t21b_8) " | " scalar(t21b_9) _newline "4-KF-FreeForm             | "  scalar(t51b_1) " | " scalar(t51b_2) "  | " scalar(t51b_3) " | " scalar(t51b_4) " | " scalar(t51b_5) " | " scalar(t51b_6) "    | " scalar(t51b_7) " | " scalar(t51b_8) " | " scalar(t51b_9) _newline "4-KS-FreeForm             | "  scalar(t22b_1) "   | " scalar(t22b_2) " | " scalar(t22b_3) " | " scalar(t22b_4) " | " scalar(t22b_5) "  | " scalar(t22b_6) " | " scalar(t22b_7) "    | " scalar(t22b_8) "    | " scalar(t22b_9)


* Table 8

clear
use bargaining_data_truth_1

* TABLE 8 ROW 1
list bargain_round total_obs_by_br total_untrue_by_br if data == 1
sum z_1

clear
use bargaining_data_truth_4

* TABLE 8 ROW 2
list bargain_round total_obs_by_br total_untrue_by_br if data == 1 & Treatment == 22
sum z_2

* TABLE 8 ROW 3
list bargain_round total_obs_by_br total_untrue_by_br if data == 1 & Treatment == 41
sum z_3

* TABLE 8 ROW 4
list bargain_round total_obs_by_br total_untrue_by_br if data == 1 & Treatment == 51
sum z_4

clear
use bargaining_data
	
/*
	FIGURES IN TABLES IN THE APPENDIX
*/


* Table 2.1.1a/b

list session treatment alternating goods surplus_known subjects_session if data_session == 1


* Table 2.1.2

* 1 good, alternating, known surplus

foreach X in -120 40 200 {

	display "Surplus = `X'"
	
	sum trade if alternating == 1 & goods == 1 & surplus == `X' & surplus_known == 1 & onetoone == 0
	sum bargaining_rounds_raw if alternating == 1 & goods == 1 & surplus == `X' & trade == 1 & surplus_known == 1 & onetoone == 0
	sum efficiency_basic if alternating == 1 & goods == 1 & surplus == `X' & surplus_known == 1 & onetoone == 0
	
	display ""
}
	sum trade if alternating == 1 & goods == 1 & surplus_known == 1 & onetoone == 0
	sum trade if alternating == 1 & goods == 1 & surplus > 0 & surplus_known == 1 & onetoone == 0
	sum bargaining_rounds_raw if alternating == 1 & goods == 1 & trade == 1 & surplus_known == 1 & onetoone == 0
	sum efficiency_basic efficiency_basic_w_t if alternating == 1 & goods == 1 & surplus_known == 1 & onetoone == 0
	

* 4 goods, alternating, known surplus, basic

	sum trade if alternating == 1 & goods == 4 & surplus_known == 1 & onetoone == 0
	sum bargaining_rounds_raw if alternating == 1 & goods == 4 & trade == 1 & surplus_known == 1 & onetoone == 0
	sum efficiency_basic efficiency_basic_w_t if alternating == 1 & goods == 4 & surplus_known == 1 & onetoone == 0

* 4 goods, alternating, known surplus, one by one

	sum trade if alternating == 1 & treatment == 61
	sum efficiency_basic efficiency_basic_w_t if treatment == 61
	

* 1 good, open chat, known surplus

foreach X in -120 40 200 {

	display "Surplus = `X'"
	
	sum trade if alternating == 0 & goods == 1 & surplus == `X' & surplus_known == 1 & onetoone == 0
	sum bargaining_rounds_raw if alternating == 0 & goods == 1 & surplus == `X' & trade == 1 & surplus_known == 1 & onetoone == 0
	sum efficiency_basic if alternating == 0 & goods == 1 & surplus == `X' & surplus_known == 1 & onetoone == 0
	
	display ""
}
	sum trade if alternating == 0 & goods == 1 & surplus_known == 1 & onetoone == 0
	sum trade if alternating == 0 & goods == 1 & surplus > 0 & surplus_known == 1 & onetoone == 0
	sum bargaining_rounds_raw if alternating == 0 & goods == 1 & trade == 1 & surplus_known == 1 & onetoone == 0
	sum efficiency_basic efficiency_basic_w_t if alternating == 0 & goods == 1 & surplus_known == 1 & onetoone == 0
	

* 4 goods, open chat, known surplus

	sum trade if alternating == 0 & goods == 4 & surplus_known == 1 & onetoone == 0
	sum bargaining_rounds_raw if alternating == 0 & goods == 4 & trade == 1 & surplus_known == 1 & onetoone == 0
	sum efficiency_basic efficiency_basic_w_t if alternating == 0 & goods == 4 & surplus_known == 1 & onetoone == 0

* 4 goods, open chat, unknown surplus, coin toss

foreach X in 10 20 30 40 50 60 70 80 100 110 120 150 160 200 {
	
	display "Surplus = `X'"
	
	sum trade if alternating == 0 & goods == 4 & surplus == `X' & surplus_known == 0 & coin == 1 & onetoone == 0
	sum bargaining_rounds if alternating == 0 & goods == 4 & surplus == `X' & trade == 1 & surplus_known == 0 & coin == 1 & onetoone == 0
	sum efficiency_basic if alternating == 0 & goods == 4 & surplus == `X' & surplus_known == 0 & coin == 1 & onetoone == 0
	
	display ""
}
	sum trade if alternating == 0 & goods == 4 & surplus_known == 0 & coin == 1 & onetoone == 0
	sum bargaining_rounds if alternating == 0 & goods == 4 & trade == 1 & surplus_known == 0 & coin == 1 & onetoone == 0
	sum efficiency_basic efficiency_basic_w_t if alternating == 0 & goods == 4 & surplus_known == 0 & coin == 1 & onetoone == 0


* 4 goods, open chat, unknown surplus, spin the wheel

foreach X in 40 70 100 {
	
	display "Surplus = `X'"
	
	sum trade if alternating == 0 & goods == 4 & surplus == `X' & surplus_known == 0 & wheel == 1 & onetoone == 0
	sum bargaining_rounds if alternating == 0 & goods == 4 & surplus == `X' & trade == 1 & surplus_known == 0 & wheel == 1 & onetoone == 0
	sum efficiency_basic if alternating == 0 & goods == 4 & surplus == `X' & surplus_known == 0 & wheel == 1 & onetoone == 0
	
	display ""
}
	sum trade if alternating == 0 & goods == 4 & surplus_known == 0 & wheel == 1 & onetoone == 0
	sum bargaining_rounds if alternating == 0 & goods == 4 & trade == 1 & surplus_known == 0 & wheel == 1 & onetoone == 0
	sum efficiency_basic efficiency_basic_w_t if alternating == 0 & goods == 4 & surplus_known == 0 & wheel == 1 & onetoone == 0
	

* All

	sum trade 
	sum trade if surplus > 0 
	sum bargaining_rounds_raw if trade == 1 
	sum efficiency_basic efficiency_basic_w 


* Table 2.2.3.1

* Test 1: Alternating treatments, known surplus, unweighted efficiency, clustered regression, period 1 only
quietly reg efficiency_basic treat if period == 1 & alternating == 1 & surplus_known == 1 & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power

* Test 2: Alternating treatments, known surplus, unweighted efficiency, t-test,
quietly ttest efficiency_basic_s_u if data_session == 1 & alternating == 1 & surplus_known == 1 & onetoone == 0, unequal by(treatment)
	scalar deg = r(N_1) + r(N_2) - 2
	scalar tc = invttail(deg,.025)
	scalar x = tc - (0.2 / r(se))
	scalar power = ttail(deg, x)
	display "Observations = " r(N_1) + r(N_2)
	display "Treatment effect = " r(mu_2) - r(mu_1)
	display "P-value = " r(p)
	display "Power = "  power

* Test 3: Alternating treatments, known surplus, unweighted efficiency, MW test
quietly ranksum efficiency_basic_s_u if data_session == 1 & alternating == 1 & surplus_known == 1 & onetoone == 0, by(treatment)
	scalar x = abs(r(z))
	display "Observations = " r(N_1) + r(N_2)
	display "P-value = " (1 - normal(x)) * 2

* Test 4: Alternating treatments, known surplus, unweighted efficiency, clustered regression, one observation per period
quietly reg efficiency_basic_p_u treat period_1 - period_5 if alternating == 1 & data_period == 1 & surplus_known == 1 & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power

* Test 5: Open chat treatments, known surplus, unweighted efficiency, clustered regression, period 1 only
quietly reg efficiency_basic treat if period == 1 & alternating == 0 & surplus_known == 1 & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power
	
* Test 6: Open chat treatments, known surplus, unweighted efficiency, t-test
quietly ttest efficiency_basic_s_u if data_session == 1 & alternating == 0 & surplus_known == 1 & onetoone == 0, unequal by(treatment)
	scalar deg = r(N_1) + r(N_2) - 2
	scalar tc = invttail(deg,.025)
	scalar x = tc - (0.2 / r(se))
	scalar power = ttail(deg, x)
	display "Observations = " r(N_1) + r(N_2)
	display "Treatment effect = " r(mu_2) - r(mu_1)
	display "P-value = " r(p)
	display "Power = "  power

* Test 7: Open chat treatments, known surplus, unweighted efficiency, MW test
quietly ranksum efficiency_basic_s_u if data_session == 1 & alternating == 0 & surplus_known == 1 & onetoone == 0, by(treatment)
	scalar x = abs(r(z))
	display "Observations = " r(N_1) + r(N_2)
	display "P-value = " (1 - normal(x)) * 2

* Test 8: Open chat treatments, known surplus, unweighted efficiency, clustered regression, one observation per period
quietly reg efficiency_basic_p_u treat period_1 - period_5 if alternating == 0 & data_period == 1 & surplus_known == 1 & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power

* Test 9: Open chat treatments, unknown surplus, coin flip, unweighted efficiency, clustered regression, period 1 only
quietly reg efficiency_basic treat if period == 1 & alternating == 0 & (treatment == 14 | treatment == 41) & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power
	
* Test 10: Open chat treatments, unknown surplus, coin flip, unweighted efficiency, t-test
quietly ttest efficiency_basic_s_u if data_session == 1 & alternating == 0 & (treatment == 14 | treatment == 41) & onetoone == 0, unequal by(treatment)
	scalar deg = r(N_1) + r(N_2) - 2
	scalar tc = invttail(deg,.025)
	scalar x = tc - (0.2 / r(se))
	scalar power = ttail(deg, x)
	display "Observations = " r(N_1) + r(N_2)
	display "Treatment effect = " r(mu_2) - r(mu_1)
	display "P-value = " r(p)
	display "Power = "  power

* Test 11: Open chat treatments, unknown surplus, coin flip, unweighted efficiency, MW test
quietly ranksum efficiency_basic_s_u if data_session == 1 & alternating == 0 & (treatment == 14 | treatment == 41) & onetoone == 0, by(treatment)
	scalar x = abs(r(z))
	display "Observations = " r(N_1) + r(N_2)
	display "P-value = " (1 - normal(x)) * 2

* Test 12: Open chat treatments, unknown surplus, coin flip, unweighted efficiency, clustered regression, one observation per period
quietly reg efficiency_basic_p_u treat period_1 - period_5 if alternating == 0 & data_period == 1 & (treatment == 14 | treatment == 41) & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power	
	
* Test 13: Open chat treatments, unknown surplus, spin the wheel, unweighted efficiency, clustered regression, period 1 only
quietly reg efficiency_basic treat if period == 1 & alternating == 0 & (treatment == 14 | treatment == 51) & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power
	
* Test 14: Open chat treatments, unknown surplus, spin the wheel, unweighted efficiency, t-test
quietly ttest efficiency_basic_s_u if data_session == 1 & alternating == 0 & (treatment == 14 | treatment == 51) & onetoone == 0, unequal by(treatment)
	scalar deg = r(N_1) + r(N_2) - 2
	scalar tc = invttail(deg,.025)
	scalar x = tc - (0.2 / r(se))
	scalar power = ttail(deg, x)
	display "Observations = " r(N_1) + r(N_2)
	display "Treatment effect = " r(mu_2) - r(mu_1)
	display "P-value = " r(p)
	display "Power = "  power

* Test 15: Open chat treatments, unknown surplus, spin the wheel, unweighted efficiency, MW test
quietly ranksum efficiency_basic_s_u if data_session == 1 & alternating == 0 & (treatment == 14 | treatment == 51) & onetoone == 0, by(treatment)
	scalar x = abs(r(z))
	display "Observations = " r(N_1) + r(N_2)
	display "P-value = " (1 - normal(x)) * 2

* Test 16: Open chat treatments, unknown surplus, spin the wheel, unweighted efficiency, clustered regression, one observation per period,
quietly reg efficiency_basic_p_u treat period_1 - period_5 if alternating == 0 & data_period == 1 & (treatment == 14 | treatment == 51) & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power	
	
* Test 17: Alternating treatments, one by one, unweighted efficiency, clustered regression, period 1 only
quietly reg efficiency_basic treat if period == 1 & (treatment == 13 | treatment == 61), cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power
	
* Test 18:  Alternating treatments, one by one, unweighted efficiency, t-test
quietly ttest efficiency_basic_s_u if data_session == 1 & (treatment == 13 | treatment == 61), unequal by(treatment)
	scalar deg = r(N_1) + r(N_2) - 2
	scalar tc = invttail(deg,.025)
	scalar x = tc - (0.2 / r(se))
	scalar power = ttail(deg, x)
	display "Observations = " r(N_1) + r(N_2)
	display "Treatment effect = " r(mu_2) - r(mu_1)
	display "P-value = " r(p)
	display "Power = "  power

* Test 19: Alternating treatments, one by one, unweighted efficiency, MW test
quietly ranksum efficiency_basic_s_u if data_session == 1 & (treatment == 13 | treatment == 61), by(treatment)
	scalar x = abs(r(z))
	display "Observations = " r(N_1) + r(N_2)
	display "P-value = " (1 - normal(x)) * 2

* Test 20: Alternating treatments, one by one, unweighted efficiency, clustered regression, one observation per period
quietly reg efficiency_basic_p_u treat period_1 - period_5 if data_period == 1 & (treatment == 13 | treatment == 61), cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power	

* Test 21: Alternating treatments, known surplus, weighted efficiency, t-test, known surplus
quietly ttest efficiency_basic_s_w if data_session == 1 & alternating == 1 & surplus_known == 1 & onetoone == 0, unequal by(treatment)
	scalar deg = r(N_1) + r(N_2) - 2
	scalar tc = invttail(deg,.025)
	scalar x = tc - (0.2 / r(se))
	scalar power = ttail(deg, x)
	display "Observations = " r(N_1) + r(N_2)
	display "Treatment effect = " r(mu_2) - r(mu_1)
	display "P-value = " r(p)
	display "Power = "  power

* Test 22: Alternating treatments, known surplus, weighted efficiency, MW test, known surplus
quietly ranksum efficiency_basic_s_w if data_session == 1 & alternating == 1 & surplus_known == 1 & onetoone == 0, by(treatment)
	scalar x = abs(r(z))
	display "Observations = " r(N_1) + r(N_2)
	display "P-value = " (1 - normal(x)) * 2

* Test 23: Alternating treatments, known surplus, weighted efficiency, clustered regression, one observation per period
quietly reg efficiency_basic_p_w treat period_1 - period_5 if alternating == 1 & data_period == 1 & surplus_known == 1 & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power
	
* Test 24: Open chat treatments, known surplus, weighted efficiency, t-test
quietly ttest efficiency_basic_s_w if data_session == 1 & alternating == 0 & surplus_known == 1 & onetoone == 0, unequal by(treatment)
	scalar deg = r(N_1) + r(N_2) - 2
	scalar tc = invttail(deg,.025)
	scalar x = tc - (0.2 / r(se))
	scalar power = ttail(deg, x)
	display "Observations = " r(N_1) + r(N_2)
	display "Treatment effect = " r(mu_2) - r(mu_1)
	display "P-value = " r(p)
	display "Power = "  power

* Test 25: Open chat treatments, known surplus, weighted efficiency, MW test,
quietly ranksum efficiency_basic_s_w if data_session == 1 & alternating == 0 & surplus_known == 1 & onetoone == 0, by(treatment)
	scalar x = abs(r(z))
	display "Observations = " r(N_1) + r(N_2)
	display "P-value = " (1 - normal(x)) * 2

* Test 26: Open chat treatments, known surplus, weighted efficiency, clustered regression, one observation per period
quietly reg efficiency_basic_p_w treat period_1 - period_5 if alternating == 0 & data_period == 1 & surplus_known == 1 & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power

* Test 27: Open chat treatments, unknown surplus, coin flip, weighted efficiency, t-test
quietly ttest efficiency_basic_s_w if data_session == 1 & alternating == 0 & (treatment == 14 | treatment == 41) & onetoone == 0, unequal by(treatment)
	scalar deg = r(N_1) + r(N_2) - 2
	scalar tc = invttail(deg,.025)
	scalar x = tc - (0.2 / r(se))
	scalar power = ttail(deg, x)
	display "Observations = " r(N_1) + r(N_2)
	display "Treatment effect = " r(mu_2) - r(mu_1)
	display "P-value = " r(p)
	display "Power = "  power

* Test 28: Open chat treatments, unknown surplus, coin flip, weighted efficiency, MW test
quietly ranksum efficiency_basic_s_w if data_session == 1 & alternating == 0 & (treatment == 14 | treatment == 41) & onetoone == 0, by(treatment)
	scalar x = abs(r(z))
	display "Observations = " r(N_1) + r(N_2)
	display "P-value = " (1 - normal(x)) * 2

* Test 29: Open chat treatments, unknown surplus, coin flip, weighted efficiency, clustered regression, one observation per period
quietly reg efficiency_basic_p_w treat period_1 - period_5 if alternating == 0 & data_period == 1 & (treatment == 14 | treatment == 41) & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power	
	
* Test 30: Open chat treatments, unknown surplus, spin the wheel, weighted efficiency, t-test
quietly ttest efficiency_basic_s_w if data_session == 1 & alternating == 0 & (treatment == 14 | treatment == 51) & onetoone == 0, unequal by(treatment)
	scalar deg = r(N_1) + r(N_2) - 2
	scalar tc = invttail(deg,.025)
	scalar x = tc - (0.2 / r(se))
	scalar power = ttail(deg, x)
	display "Observations = " r(N_1) + r(N_2)
	display "Treatment effect = " r(mu_2) - r(mu_1)
	display "P-value = " r(p)
	display "Power = "  power

* Test 31: Open chat treatments, unknown surplus, spin the wheel, weighted efficiency, MW test
quietly ranksum efficiency_basic_s_w if data_session == 1 & alternating == 0 & (treatment == 14 | treatment == 51) & onetoone == 0, by(treatment)
	scalar x = abs(r(z))
	display "Observations = " r(N_1) + r(N_2)
	display "P-value = " (1 - normal(x)) * 2

* Test 32: Open chat treatments, unknown surplus, spin the wheel, ueighted efficiency, clustered regression, one observation per period,
quietly reg efficiency_basic_p_w treat period_1 - period_5 if alternating == 0 & data_period == 1 & (treatment == 14 | treatment == 51) & onetoone == 0, cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power	

* Test 33: Alternating treatments, one by one, weighted efficiency, t-test
quietly ttest efficiency_basic_s_w if data_session == 1 & (treatment == 13 | treatment == 61), unequal by(treatment)
	scalar deg = r(N_1) + r(N_2) - 2
	scalar tc = invttail(deg,.025)
	scalar x = tc - (0.2 / r(se))
	scalar power = ttail(deg, x)
	display "Observations = " r(N_1) + r(N_2)
	display "Treatment effect = " r(mu_2) - r(mu_1)
	display "P-value = " r(p)
	display "Power = "  power

* Test 34: Alternating treatments, one by one, weighted efficiency, MW test
quietly ranksum efficiency_basic_s_w if data_session == 1 & (treatment == 13 | treatment == 61), by(treatment)
	scalar x = abs(r(z))
	display "Observations = " r(N_1) + r(N_2)
	display "P-value = " (1 - normal(x)) * 2

* Test 35: Alternating treatments, one by one, weighted efficiency, clustered regression, one observation per period
quietly reg efficiency_basic_p_w treat period_1 - period_5 if data_period == 1 & (treatment == 13 | treatment == 61), cluster(session)
	scalar deg = e(N_clust) - 1
	scalar tc = invttail(deg, 0.025)
	scalar x = tc - (0.2 / _se[treat])
	scalar power = ttail(deg, x)
	scalar y = _b[treat] / _se[treat]
	scalar z = 2 * ttail(deg, y)
	display "Observations = " e(N)
	display "Treatment effect = " _b[treat]
	display "P-value = " z
	display "Power = " power	


log close
